package com.example.zhu95.mytimber.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.example.zhu95.mytimber.PlayMusicService;

import static com.example.zhu95.mytimber.ConstantValue.CURRENT_POSITION;
import static com.example.zhu95.mytimber.ConstantValue.PlayMusicCmd;
import static com.example.zhu95.mytimber.ConstantValue.PlayMusicCmd_CurrentPosition;
import static com.example.zhu95.mytimber.ConstantValue.PlayMusicCmd_Pause;
import static com.example.zhu95.mytimber.ConstantValue.PlayMusicCmd_Play;
import static com.example.zhu95.mytimber.ConstantValue.PlayMusicCmd_Stop;
import static com.example.zhu95.mytimber.ConstantValue.SONG_ID;
import static com.example.zhu95.mytimber.ConstantValue.SONG_IDS;

/**
 * @author zhu95
 * @date 2018/3/16 19:08
 */
public class StartPlayReceiver extends BroadcastReceiver {
    PlayMusicService service;

    public StartPlayReceiver(PlayMusicService service) {
        this.service = service;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        PlayMusicService.PlayMusicBinder playMusicBinder = service.getPlayMusicBinder();
        int songid = intent.getIntExtra(SONG_ID, -1);
        String songids = intent.getStringExtra(SONG_IDS);
        String cmd = intent.getStringExtra(PlayMusicCmd);
        int currentPosition = intent.getIntExtra(CURRENT_POSITION, -1);
        switch (cmd) {
            case PlayMusicCmd_Play:
                //播放歌曲
                playMusicBinder.playMusic(songid, songids);
                if (currentPosition >= 0) {
                    playMusicBinder.setCurrentPosition(currentPosition);
                }
                break;
            case PlayMusicCmd_Pause:
                playMusicBinder.pauseMusic();
                break;
            case PlayMusicCmd_Stop:
                playMusicBinder.stopMusic();
                break;
            case PlayMusicCmd_CurrentPosition:
                playMusicBinder.setCurrentPosition(currentPosition);
                break;
            default:
        }
    }

}
